<?php
/**
 * 中轩首页模块微站定义
 *
 * @author zhongxuan
 * @url http://bbs.we7.cc
 */
defined('IN_IA') or exit('Access Denied');

class Zh_shouye1ModuleSite extends WeModuleSite {

	/**
	 * 广告管理开始   
	 **/
	public function doWebAdlist() {
		
		global $_W, $_GPC;
		//$work_Log=pdo_getall('zh_lvsh_riji',array('uniacid'=>$_W['uniacid']));
		$sql="select * from ".tablename('bd_cms_ad')." where uniacid=".$_W['uniacid'];
		
		if($_GPC['ad_title']){
			$sql=$sql." and ad_title like '%".$_GPC['ad_title']."%'";
		}
		
		$ad_list=pdo_fetchall($sql);
		//分页
		$total=count($ad_list);
		$pageindex=max($_GPC['page'],1);
		$pagesize=10;
		$pager=pagination($total,$pageindex,$pagesize);
		$p=($pageindex-1)*$pagesize;
		$sql.=" order by ad_id desc limit ".$p." , ".$pagesize;
		//分页结束
		$work_Log=pdo_fetchall($sql);

		var_dump($work_Log);die;
		load()->func('tpl');
        include $this->template('ad_list');
	}
	
	
	//*************** 编辑与添加****************************//
	public function doWebAdedit() {
		global $_W, $_GPC;
		if($_GET['ad_id']){
			$ad=pdo_get('bd_cms_ad',array('ad_id'=>$_GET['ad_id']));
		}
		load()->func('tpl');
        include $this->template('ad_edit');
		
		
	}
	//*************** 保存数据****************************//
	public function doWebAdsave(){
		
		global $_W, $_GPC;
		
		$data=$_POST;
		$data['last_time']=date('Y-m-d H:i:s');
		if($_POST['ad_id']){
			$res=pdo_update('bd_cms_ad',$data,array('ad_id'=>$_POST['ad_id']));
		}else{
			$data['uid']=$_W['uid'];
			$data['uniacid']=$_W['uniacid'];
			$data['add_time']=date('Y-m-d H:i:s');
			$res=pdo_insert('bd_cms_ad',$data);
		}
		
		if($res){
			message('保存成功!',$this->createWebUrl('adlist'));
		}else{
			message('操作失败','referer','error');
		}
	}
		//*************** 编辑与添加****************************//
	public function doWebAddel() {
		
		global $_W, $_GPC;
		
		if($_GET['ad_id']){
			$res = pdo_delete('bd_cms_ad', array('ad_id' => $_GET['ad_id']));
		}
		if($res){
			message('删除成功!',$this->createWebUrl('adlist'));
		}else{
			message('操作失败','referer','error');
		}
	}
	
	/**
	 * 广告管理结束
	 **/	
	
	
//*************** 文章管理开始****************************//
//*************** 文章开始****************************//	
	public function doWebArticlelist() {
		//这个操作被定义用来呈现 管理中心导航菜单
		
		global $_W, $_GPC;
        // 分类
		$categorys=pdo_getall('bd_cms_category',array('uniacid'=>$_W['uniacid']));
		
		
		//文章列表
		$sql="select * from ".tablename('bd_cms_article')." where uniacid=".$_W['uniacid'];
		if($_GPC['cat_id']){
			$sql=$sql." and article_cat=".$_GPC['cat_id'];
		}
		if($_GPC['article_title']){
			$sql=$sql." and article_title like '%".$_GPC['article_title']."%'";
		}
		if($_GPC['add_time']){
			$sql=$sql." and add_time>= '".date("Y-m-d",strtotime("-$_GPC[add_time] days"))."'";
		}
		
		$article_list=pdo_fetchall($sql);
		//分页
		$total=count($article_list);
		$pageindex=max($_GPC['page'],1);
		$pagesize=10;
		$pager=pagination($total,$pageindex,$pagesize);
		$p=($pageindex-1)*$pagesize;
		$sql.=" order by article_sort desc limit ".$p." , ".$pagesize;
		//分页结束
		$article_list=pdo_fetchall($sql);
		foreach($article_list as &$article){
			$article['article_cat']=pdo_getcolumn('bd_cms_category', array('cat_id' => $article['article_cat']), 'cat_name');
		}
		
		load()->func('tpl');
        include $this->template('article_list');
	}	
		//*************** 编辑与添加****************************//
	public function doWebArticleedit() {
		global $_W, $_GPC;
		// 分类
		$categorys=pdo_getall('bd_cms_category',array('uniacid'=>$_W['uniacid']));
		
		if($_GET['article_id']){
			$article=pdo_get('bd_cms_article',array('article_id'=>$_GET['article_id']));
		}
		load()->func('tpl');
        include $this->template('article_edit');
		
		
	}
	//*************** 保存数据****************************//
	public function doWebArticlesave(){
		global $_W, $_GPC;
		$data=$_POST;
		$data['last_time']=date("Y-m-d H:i:s");
		$data['status']=1;
		if($_POST['article_id']){
			$res=pdo_update('bd_cms_article',$data,array('article_id'=>$data['article_id']));
		}else{
			$data['uid']=$_W['uid'];
			$data['uniacid']=$_W['uniacid'];
			$data['add_time']=date("Y-m-d H:i:s");
			$res=pdo_insert('bd_cms_article',$data);
		}
		
		if($res){
			message('操作成功!',$this->createWebUrl('articlelist'));
		}else{
			message('操作失败','referer','error');
		}
	}
		//*****删除*************//
	public function doWebArticledel() {
		global $_W, $_GPC;
		if($_GET['article_id']){
			$res = pdo_delete('bd_cms_article', array('article_id' => $_GET['article_id']));
		}
		if($res){
			message('删除成功!',$this->createWebUrl('articlelist'));
		}else{
			message('删除成功!','referer','error');
		}
	}
	
	
	
	
	
//*************** 文章管理结束****************************//
//*************** 文章分类开始****************************
	public function doWebCategory() {
		//这个操作被定义用来呈现 管理中心导航菜单
		
		global $_W, $_GPC;
        // 将渲染模块目录下的web端的模板文件
		//$work_Log=pdo_getall('zh_lvsh_riji',array('uniacid'=>$_W['uniacid']));
		$sql="select * from ".tablename('bd_cms_category')." where uniacid=".$_W['uniacid'];
		$catagory_list=pdo_fetchall($sql);
		//分页
		$total=count($catagory_list);
		$pageindex=max($_GPC['page'],1);
		$pagesize=10;
		$pager=pagination($total,$pageindex,$pagesize);
		$p=($pageindex-1)*$pagesize;
		$sql.=" order by cat_sort desc limit ".$p." , ".$pagesize;
		//分页结束
		$catagory_list=pdo_fetchall($sql);


		load()->func('tpl');
        include $this->template('category_list');
	}	
	//*************** 编辑与添加****************************//
	public function doWebCategoryedit() {
		global $_W, $_GPC;
		// 分类
		if($_GET['cat_id']){
			$category=pdo_get('bd_cms_category',array('cat_id'=>$_GET['cat_id']));
			$$category['true_image']=tomedia($category['cat_logo']);
		}
		load()->func('tpl');
		include $this->template('category_edit');
	
	
	}
	//*************** 保存数据****************************//
	public function doWebCategorysave(){
		global $_W, $_GPC;
		$data=$_POST;
		$data['last_time']=date("Y-m-d H:i:s");
		$data['status']=1;
		if($_POST['cat_id']){
			$res=pdo_update('bd_cms_category',$data,array('cat_id'=>$data['cat_id']));
		}else{
			$data['uid']=$_W['uid'];
			$data['uniacid']=$_W['uniacid'];
			$data['add_time']=date("Y-m-d H:i:s");
			$res=pdo_insert('bd_cms_category',$data);
		}
	
		if($res){
			message('操作成功!',$this->createWebUrl('category'));
		}else{
			message('删除成功!','referer','error');
		}
	}
	//*****删除*************//
	public function doWebCategorydel() {
		global $_W, $_GPC;
		if($_GET['cat_id']){
			if(pdo_get('bd_cms_article',array('article_cat'=>$_GET['cat_id']))){
				$msg='此分类下有所属文章,不可删除';
			}else{
				$res = pdo_delete('bd_cms_category', array('cat_id' => $_GET['cat_id']));
				$msg='删除成功!';
			}
		}
		if($res){
			message($msg,$this->createWebUrl('category'));
		}else{
			$msg='参数有误,删除失败';
			message($msg,'referer','error');
		}
	}
	
	
	
	//*************** 文章分类结束****************************//
	//*************** 文章公告开始****************************//
	
	
	public function doWebNotice() {

		global $_W, $_GPC;
		$sql="select * from ".tablename('bd_cms_notice')." where uniacid=".$_W['uniacid'];
		if($_GPC['notice_title']){
			$sql=$sql." and notice_title like '%".$_GPC['notice_title']."%'";
		}
		if($_GPC['add_time']){
			$sql=$sql." and add_time>= '".date("Y-m-d",strtotime("-$_GPC[add_time] days"))."'";
		}
		$notice_list=pdo_fetchall($sql);
		//分页
		$total=count($notice_list);
		$pageindex=max($_GPC['page'],1);
		$pagesize=10;
		$pager=pagination($total,$pageindex,$pagesize);
		$p=($pageindex-1)*$pagesize;
		$sql.=" order by notice_sort desc limit ".$p." , ".$pagesize;
		//分页结束
		$notice_list=pdo_fetchall($sql);
		
		load()->func('tpl');
		include $this->template('notice_list');
	}
	
	//*************** 编辑与添加****************************//
	public function doWebNoticeedit() {
		global $_W, $_GPC;
	
		if($_GET['notice_id']){
			$notice=pdo_get('bd_cms_notice',array('notice_id'=>$_GET['notice_id']));
		}
		load()->func('tpl');
		include $this->template('notice_edit');
	
	
	}
	//*************** 保存数据****************************//
	public function doWebNoticesave(){
		global $_W, $_GPC;
		$data=$_POST;
		$data['last_time']=date("Y-m-d H:i:s");
		$data['status']=1;
		if($_POST['notice_id']){
			$res=pdo_update('bd_cms_notice',$data,array('notice_id'=>$data['notice_id']));
		}else{
			$data['uid']=$_W['uid'];
			$data['uniacid']=$_W['uniacid'];
			$data['add_time']=date("Y-m-d H:i:s");
			$res=pdo_insert('bd_cms_notice',$data);
		}
	
		if($res){
			message('操作成功!',$this->createWebUrl('notice'));
		}else{
			message('操作失败','referer','error');
		}
	}
	//*****删除*************//
	public function doWebNoticedel() {
		global $_W, $_GPC;
		if($_GET['notice_id']){
			$res = pdo_delete('bd_cms_notice', array('notice_id' => $_GET['notice_id']));
		}
		if($res){
			message('删除成功!',$this->createWebUrl('notice'));
		}else{
			message('参数有误,删除失败!','referer','error');
		}
	}
	
	
	
	
	//*************** 文章分类结束****************************//
	
	
	//*************** 产品管理开始****************************//
	
	
	
	public function doWebProductlist() {

		global $_W, $_GPC;
		$sql="select * from ".tablename('bd_mis_product')." where uniacid=".$_W['uniacid'];
		if($_GPC['product_name']){
			$sql=$sql." and product_name like '%".$_GPC['product_name']."%'";
		}
		if($_GPC['add_time']){
			$sql=$sql." and add_time>= '".date("Y-m-d",strtotime("-$_GPC[add_time] days"))."'";
		}
		$product_list=pdo_fetchall($sql);
		//分页
		$total=count($product_list);
		$pageindex=max($_GPC['page'],1);
		$pagesize=10;
		$pager=pagination($total,$pageindex,$pagesize);
		$p=($pageindex-1)*$pagesize;
		$sql.=" order by product_id desc limit ".$p." , ".$pagesize;
		//分页结束
		$product_list=pdo_fetchall($sql);
		foreach($product_list as &$pro){
			$pro['product_thumb']=tomedia($pro['product_thumb']);
		}
		
		load()->func('tpl');
		include $this->template('product_list');
	}
	
	//*************** 编辑与添加****************************//
	public function doWebProductedit() {
		global $_W, $_GPC;
	
		if($_GET['product_id']){
			$product=pdo_get('bd_mis_product',array('product_id'=>$_GET['product_id']));
		}
		load()->func('tpl');
		include $this->template('product_edit');
	
	
	}
	//*************** 保存数据****************************//
	public function doWebProductsave(){
		global $_W, $_GPC;
		$data=$_POST;
		$data['last_time']=date("Y-m-d H:i:s");
		$data['status']=1;
		if($_POST['product_id']){
			$res=pdo_update('bd_mis_product',$data,array('product_id'=>$data['product_id']));
		}else{
			$data['uid']=$_W['uid'];
			$data['uniacid']=$_W['uniacid'];
			$data['add_time']=date("Y-m-d H:i:s");
			$res=pdo_insert('bd_mis_product',$data);
		}
	
		if($res){
			message('操作成功!',$this->createWebUrl('productlist'));
		}else{
			message('操作失败','referer','error');
		}
	}
	//*****删除*************//
	public function doWebProductdel() {
		global $_W, $_GPC;
		if($_GET['product_id']){
			$res = pdo_delete('bd_mis_product', array('product_id' => $_GET['product_id']));
		}
		if($res){
			message('删除成功!',$this->createWebUrl('productlist'));
		}else{
			message('参数有误,删除失败!','referer','error');
		}
	}
	
	
	

	//*************** 产品结束****************************//
	
	
	//*************** 案例开始****************************//
	
	
	
	public function doWebCaselist() {
	
		global $_W, $_GPC;
		$sql="select * from ".tablename('bd_mis_case')." where uniacid=".$_W['uniacid'];
		if($_GPC['case_name']){
			$sql=$sql." and case_name like '%".$_GPC['case_name']."%'";
		}
		if($_GPC['add_time']){
			$sql=$sql." and add_time>= '".date("Y-m-d",strtotime("-$_GPC[add_time] days"))."'";
		}
		$case_list=pdo_fetchall($sql);
		//分页
		$total=count($case_list);
		$pageindex=max($_GPC['page'],1);
		$pagesize=10;
		$pager=pagination($total,$pageindex,$pagesize);
		$p=($pageindex-1)*$pagesize;
		$sql.=" order by case_id desc limit ".$p." , ".$pagesize;
		//分页结束
		$case_list=pdo_fetchall($sql);
		foreach($case_list as &$pro){
			$pro['case_thumb']=tomedia($pro['case_thumb']);
		}
	
		load()->func('tpl');
		include $this->template('case_list');
	}
	
	//*************** 编辑与添加****************************//
	public function doWebCaseedit() {
		global $_W, $_GPC;
	
		if($_GET['case_id']){
			$case=pdo_get('bd_mis_case',array('case_id'=>$_GET['case_id']));
		}
		load()->func('tpl');
		include $this->template('case_edit');
	
	
	}
	//*************** 保存数据****************************//
	public function doWebCasesave(){
		global $_W, $_GPC;
		$data=$_POST;
		$data['last_time']=date("Y-m-d H:i:s");
		$data['status']=1;
		if($_POST['case_id']){
			$res=pdo_update('bd_mis_case',$data,array('case_id'=>$data['case_id']));
		}else{
			$data['uid']=$_W['uid'];
			$data['uniacid']=$_W['uniacid'];
			$data['add_time']=date("Y-m-d H:i:s");
			$res=pdo_insert('bd_mis_case',$data);
		}
	
		if($res){
			message('操作成功!',$this->createWebUrl('caselist'));
		}else{
			message('操作失败','referer','error');
		}
	}
	//*****删除*************//
	public function doWebCasedel() {
		global $_W, $_GPC;
		if($_GET['case_id']){
			$res = pdo_delete('bd_mis_case', array('case_id' => $_GET['case_id']));
		}
		if($res){
			message('删除成功!',$this->createWebUrl('caselist'));
		}else{
			message('参数有误,删除失败!','referer','error');
		}
	}
	
	
	//*************** 案例结束****************************//
	
	
	//*************** 招聘开始****************************//
	
	
	
	
	public function doWebRecruitlist() {
	
		global $_W, $_GPC;
		$sql="select * from ".tablename('bd_mis_recruit')." where uniacid=".$_W['uniacid'];
		if($_GPC['recruit_title']){
			$sql=$sql." and recruit_title like '%".$_GPC['recruit_title']."%'";
		}
		if($_GPC['add_time']){
			$sql=$sql." and add_time>= '".date("Y-m-d",strtotime("-$_GPC[add_time] days"))."'";
		}
		$recruit_list=pdo_fetchall($sql);
		//分页
		$total=count($recruit_list);
		$pageindex=max($_GPC['page'],1);
		$pagesize=10;
		$pager=pagination($total,$pageindex,$pagesize);
		$p=($pageindex-1)*$pagesize;
		$sql.=" order by recruit_id desc limit ".$p." , ".$pagesize;
		//分页结束
		$recruit_list=pdo_fetchall($sql);
		foreach($recruit_list as &$pro){
			$pro['recruit_thumb']=tomedia($pro['recruit_thumb']);
		}
	
		load()->func('tpl');
		include $this->template('recruit_list');
	}
	
	//*************** 编辑与添加****************************//
	public function doWebRecruitedit() {
		global $_W, $_GPC;
	
		if($_GET['recruit_id']){
			$recruit=pdo_get('bd_mis_recruit',array('recruit_id'=>$_GET['recruit_id']));
		}
		load()->func('tpl');
		include $this->template('recruit_edit');
	
	
	}
	//*************** 保存数据****************************//
	public function doWebRecruitsave(){
		global $_W, $_GPC;
		$data=$_POST;
		$data['last_time']=date("Y-m-d H:i:s");
		$data['status']=1;
		if($_POST['recruit_id']){
			$res=pdo_update('bd_mis_recruit',$data,array('recruit_id'=>$data['recruit_id']));
		}else{
			$data['uid']=$_W['uid'];
			$data['uniacid']=$_W['uniacid'];
			$data['add_time']=date("Y-m-d H:i:s");
			$res=pdo_insert('bd_mis_recruit',$data);
		}
	
		if($res){
			message('操作成功!',$this->createWebUrl('recruitlist'));
		}else{
			message('操作失败','referer','error');
		}
	}
	//*****删除*************//
	public function doWebRecruitdel() {
		global $_W, $_GPC;
		if($_GET['recruit_id']){
			$res = pdo_delete('bd_mis_recruit', array('recruit_id' => $_GET['recruit_id']));
		}
		if($res){
			message('删除成功!',$this->createWebUrl('recruitlist'));
		}else{
			message('参数有误,删除失败!','referer','error');
		}
	}
	
	
	

	//*************** 招聘结束****************************//
	
	
	//*************** 系统配置开始****************************//
	//*************** 系统配置公司信息开始****************************//
	public function doWebConfigenterprise(){
		global $_W, $_GPC;
		
		$config_group='enterprise';
		
		$list=pdo_getall('bd_sys_config',array('uniacid'=>$_W['uniacid'],'config_group'=>'enterprise','status'=>1));
		$config_row=array();
		foreach ($list as &$conf){
			$config_row[$conf['config_code']]=$conf['config_value'];
		}
		load()->func('tpl');
		include $this->template('config_index');
	}
	
	/**
	 * @name  doWebConfigsave()
	 * @desc  保存系统配置列表数据
	 * @author xiaolonglong
	 * @updatetime  2018年4月26日
	 * @version 1.0.0
	 */
	public function doWebConfigsave(){
		global $_W, $_GPC;
		$config_list=$_POST;
		foreach ($config_list as $key=>$value ){
			$data['uid']=$_W['uid'];
			$data['uniacid']=$_W['uniacid'];
			$data['config_value']=$value;
			$data['last_time']=date('Y-m-d H:i:s');
			
			$has=pdo_get('bd_sys_config',array('config_code'=>$key,'uniacid'=>$_W['uniacid']));
			if($has){
				$res=pdo_update('bd_sys_config',$conf,array('config_code'=>$key,'uniacid'=>$_W['uniacid']));
			}else{
				$conf=array(
						'config_code'=>$key,
						'config_type'=>'text',
						'config_group'=>$_GPC['config_group'],
						'status'=>1,
						'uid'=>$_W['uid'],
						'uniacid'=>$_W['uniacid'],
						'config_value'=>$value,
						'add_time'=>date('Y-m-d H:i:s'),
						'last_time'=>date('Y-m-d H:i:s')
				);
				$res=pdo_insert('bd_sys_config',$conf);
			}
		}
		if($res){
			message('修改成功!','referer','success');
		}else{
			message('参数有误,修改失败!','referer','error');
		}
	}
	
	public function doWebConfigwebset(){
		global $_W, $_GPC;
	
		$config_group='basic';
		
		$list=pdo_getall('bd_sys_config',array('uniacid'=>$_W['uniacid'],'config_group'=>$config_group,'status'=>1));
		$config_row=array();
		foreach ($list as &$conf){
			$config_row[$conf['config_code']]=$conf['config_value'];
		}
	
		load()->func('tpl');
		include $this->template('config_index');
	}
	
	
	
	
	//*************** 公司信息结束****************************//
	//*************** 网站信息开始****************************//
	
	
	
	public function doWebGuestbook() {
	
		global $_W, $_GPC;
		$sql="select * from ".tablename('bd_cms_guestbook')." where uniacid=".$_W['uniacid'];
		if($_GPC['guestbook_name']){
			$sql=$sql." and guestbook_name like '%".$_GPC['guestbook_name']."%'";
		}
		if($_GPC['add_time']){
			$sql=$sql." and add_time>= '".date("Y-m-d",strtotime("-$_GPC[add_time] days"))."'";
		}
		$guestbook_list=pdo_fetchall($sql);
		//分页
		$total=count($guestbook_list);
		$pageindex=max($_GPC['page'],1);
		$pagesize=10;
		$pager=pagination($total,$pageindex,$pagesize);
		$p=($pageindex-1)*$pagesize;
		$sql.=" order by guestbook_id desc limit ".$p." , ".$pagesize;
		//分页结束
		$guestbook_list=pdo_fetchall($sql);
	
		load()->func('tpl');
		include $this->template('guestbook_list');
	}
	
	
	
	//*************** 网站信息结束****************************//
	//*************** 小程序banner开始 20180517****************************//
	
	public function doWebBannerlist() {
	
		global $_W, $_GPC;
		$sql="select * from ".tablename('bd_banner')." where uniacid=".$_W['uniacid'];
		if($_GPC['banner_title']){
			$sql=$sql." and banner_title like '%".$_GPC['banner_title']."%'";
		}
		if($_GPC['add_time']){
			$sql=$sql." and add_time>= '".date("Y-m-d",strtotime("-$_GPC[add_time] days"))."'";
		}
		$banner_list=pdo_fetchall($sql);
		//分页
		$total=count($banner_list);
		$pageindex=max($_GPC['page'],1);
		$pagesize=10;
		$pager=pagination($total,$pageindex,$pagesize);
		$p=($pageindex-1)*$pagesize;
		$sql.=" order by banner_sort desc limit ".$p." , ".$pagesize;
		//分页结束
		$banner_list=pdo_fetchall($sql);
		foreach($banner_list as &$pro){
			$pro['banner_thumb']=tomedia($pro['banner_thumb']);
		}
	
		load()->func('tpl');
		include $this->template('banner_list');
	}
	
	//*************** 编辑与添加****************************//
	public function doWebBanneredit() {
		global $_W, $_GPC;
	
		if($_GET['banner_id']){
			$banner=pdo_get('bd_banner',array('banner_id'=>$_GET['banner_id']));
		}
		load()->func('tpl');
		include $this->template('banner_edit');
	
	
	}
	//*************** 保存数据****************************//
	public function doWebBannersave(){
		global $_W, $_GPC;
		$data=$_POST;
		$data['last_time']=date("Y-m-d H:i:s");
		$data['status']=1;
		if($_POST['banner_id']){
			$res=pdo_update('bd_banner',$data,array('banner_id'=>$data['banner_id']));
		}else{
			$data['uid']=$_W['uid'];
			$data['uniacid']=$_W['uniacid'];
			$data['add_time']=date("Y-m-d H:i:s");
			$res=pdo_insert('bd_banner',$data);
		}
	
		if($res){
			message('操作成功!',$this->createWebUrl('bannerlist'));
		}else{
			message('操作失败','referer','error');
		}
	}
	//*****删除*************//
	public function doWebBannerdel() {
		global $_W, $_GPC;
		if($_GET['banner_id']){
			$res = pdo_delete('bd_banner', array('banner_id' => $_GET['banner_id']));
		}
		if($res){
			message('删除成功!',$this->createWebUrl('bannerlist'));
		}else{
			message('参数有误,删除失败!','referer','error');
		}
	}

}